package org.films.web;

import java.lang.Long;
import java.lang.String;
import javax.validation.Valid;
import org.films.domain.Actor;
import org.films.domain.Film;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

privileged aspect ActorController_Roo_Controller {
    
    @RequestMapping(value = "/actor", method = RequestMethod.POST)    
    public String ActorController.create(@Valid Actor actor, BindingResult result, ModelMap modelMap) {    
        if (actor == null) throw new IllegalArgumentException("A actor is required");        
        if (result.hasErrors()) {        
            modelMap.addAttribute("films", Film.findAllFilms());            
            modelMap.addAttribute("actor_birthDay_date_format", org.joda.time.format.DateTimeFormat.patternForStyle("S-", org.springframework.context.i18n.LocaleContextHolder.getLocale()));            
            return "actor/create";            
        }        
        actor.persist();        
        return "redirect:/actor/" + actor.getId();        
    }    
    
    @RequestMapping(value = "/actor/form", method = RequestMethod.GET)    
    public String ActorController.createForm(ModelMap modelMap) {    
        modelMap.addAttribute("actor", new Actor());        
        modelMap.addAttribute("films", Film.findAllFilms());        
        modelMap.addAttribute("actor_birthDay_date_format", org.joda.time.format.DateTimeFormat.patternForStyle("S-", org.springframework.context.i18n.LocaleContextHolder.getLocale()));        
        return "actor/create";        
    }    
    
    @RequestMapping(value = "/actor/{id}", method = RequestMethod.GET)    
    public String ActorController.show(@PathVariable("id") Long id, ModelMap modelMap) {    
        if (id == null) throw new IllegalArgumentException("An Identifier is required");        
        modelMap.addAttribute("actor_birthDay_date_format", org.joda.time.format.DateTimeFormat.patternForStyle("S-", org.springframework.context.i18n.LocaleContextHolder.getLocale()));        
        modelMap.addAttribute("actor", Actor.findActor(id));        
        return "actor/show";        
    }    
    
    @RequestMapping(value = "/actor", method = RequestMethod.GET)    
    public String ActorController.list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, ModelMap modelMap) {    
        if (page != null || size != null) {        
            int sizeNo = size == null ? 10 : size.intValue();            
            modelMap.addAttribute("actors", Actor.findActorEntries(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo));            
            float nrOfPages = (float) Actor.countActors() / sizeNo;            
            modelMap.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));            
        } else {        
            modelMap.addAttribute("actors", Actor.findAllActors());            
        }        
        modelMap.addAttribute("actor_birthDay_date_format", org.joda.time.format.DateTimeFormat.patternForStyle("S-", org.springframework.context.i18n.LocaleContextHolder.getLocale()));        
        return "actor/list";        
    }    
    
    @RequestMapping(method = RequestMethod.PUT)    
    public String ActorController.update(@Valid Actor actor, BindingResult result, ModelMap modelMap) {    
        if (actor == null) throw new IllegalArgumentException("A actor is required");        
        if (result.hasErrors()) {        
            modelMap.addAttribute("films", Film.findAllFilms());            
            modelMap.addAttribute("actor_birthDay_date_format", org.joda.time.format.DateTimeFormat.patternForStyle("S-", org.springframework.context.i18n.LocaleContextHolder.getLocale()));            
            return "actor/update";            
        }        
        actor.merge();        
        return "redirect:/actor/" + actor.getId();        
    }    
    
    @RequestMapping(value = "/actor/{id}/form", method = RequestMethod.GET)    
    public String ActorController.updateForm(@PathVariable("id") Long id, ModelMap modelMap) {    
        if (id == null) throw new IllegalArgumentException("An Identifier is required");        
        modelMap.addAttribute("actor", Actor.findActor(id));        
        modelMap.addAttribute("films", Film.findAllFilms());        
        modelMap.addAttribute("actor_birthDay_date_format", org.joda.time.format.DateTimeFormat.patternForStyle("S-", org.springframework.context.i18n.LocaleContextHolder.getLocale()));        
        return "actor/update";        
    }    
    
    @RequestMapping(value = "/actor/{id}", method = RequestMethod.DELETE)    
    public String ActorController.delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size) {    
        if (id == null) throw new IllegalArgumentException("An Identifier is required");        
        Actor.findActor(id).remove();        
        return "redirect:/actor?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString());        
    }    
    
}
